// 指向-计时
class point extends eui.Component{
    private timeTx:eui.BitmapLabel;
    private pointMc:eui.Image;
    private pointBg:eui.Image;

    public constructor(){
        super();
        this.once(eui.UIEvent.COMPLETE,this.onComplete,this);
        this.skinName = "src/Game/gameRoom/centerPoker/pointSkin.exml";
    }
    private onComplete(){
        this.init();
        this.once(egret.Event.REMOVED_FROM_STAGE,this.onRemove,this);
    }
    private onRemove(){
        egret.Tween.removeTweens(this.pointMc);
        this.timer.reset();
        this.timer.stop();
        this.timer.removeEventListener(egret.TimerEvent.TIMER,this.onTimer,this);
        this.timer.removeEventListener(egret.TimerEvent.COMPLETE,this.onTimerComplete,this);
    }

    private time:number = 60;
    private currentTime:number;
    private timeValue:string = "00";
    private timer:egret.Timer = new egret.Timer(1000,this.time);
    private init(){
        this.pointMc.visible = false;
        this.timer.addEventListener(egret.TimerEvent.TIMER,this.onTimer,this);
        this.timer.addEventListener(egret.TimerEvent.COMPLETE,this.onTimerComplete,this);
    }
    private onTimerComplete(e:egret.Timer){
        this.dispatchEventWith(PointEvent.POINT_TIMERCOMPLETE);
    }
    //启动计时器
    private startTimer(){
        this.currentTime = this.time;
        this.timeValue = ""+this.currentTime;
        this.timeTx.text = this.timeValue;
        this.timer.stop();
        this.timer.reset();
        this.timer.start();
    }
    private onTimer(e:egret.TimerEvent){
        this.currentTime --;
        if(this.currentTime<10){
            this.timeValue = "0"+this.currentTime;
        }else{
            this.timeValue = ""+this.currentTime;
        }
        this.timeTx.text = this.timeValue;
        this.timeTx.x = (this.pointMc.width - this.timeTx.textWidth)/2;
        this.timeTx.y = (this.pointMc.height - this.timeTx.textHeight)/2;
    }
    
    //刷新数据 (指向1-4)
    private pointRotation:Array<number> = [180,-90,0,90];
    public updateData(mySeatIndex:number,OriginalPoint:number){//(转换座位，原始座位)；
        if(OriginalPoint<5&&OriginalPoint>0){
            //alert("方向：");
            this.pointMc.source = "point_"+(OriginalPoint)+"_png";
            this.pointMc.visible = true;
            this.pointBg.rotation = this.pointRotation[mySeatIndex];
            this.pointMc.rotation = this.pointBg.rotation;
            egret.Tween.removeTweens(this.pointMc); 
            this.pointMc.alpha = 1;
            egret.Tween.get(this.pointMc,{"loop":true}).to({alpha:0},500).to({alpha:1},500);
            this.startTimer();
        }else if (OriginalPoint === -1){
            this.pointMc.visible = false;
        }
    }
}